{% extends "base.html" %}
{% block title %}申请单列表{% endblock %}
{% block head %}
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    {{ super() }}
    <style>
        .weui-cells__title {
            padding-left: 0;
        }

        .sheetList {
            display: none;
            background: #efeff4;
            border-left: 5px solid red;
        }

    </style>
{% endblock %}
{% block body %}
    <div class="contianer">
        <div class="mine-page" style="overflow-y: hidden">
            <div class="ccdList-page" style="overflow-x: hidden;top: 4em;">
                <div class="weui-pull-to-refresh__layer" style="padding:7px;">
                    <div class='weui-pull-to-refresh__arrow'></div>
                    <div class='weui-pull-to-refresh__preloader'></div>
                    <div class="down">下拉刷新</div>
                    <div class="up">释放刷新</div>
                    <div class="refresh">正在刷新</div>
                </div>

                <div id="ccd-list" style="top:3em;">
                </div>
                <div class="weui-infinite-scroll" style="display: none;">
                    <div class="infinite-preloader"></div>
                    <div class="weui-loadmore" style="margin: 0 auto">
                        <i class="weui-loading"></i>
                        <span class="weui-loadmore__tips">正在加载</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block script %}
    {{ super() }}
    <script type="text/javascript">

        var cacheDataList = null;
        var select_type = 3;
        var select_time = 0;
        var user_id = common.getQueryString("user_id");

        $(function () {
            getCCDList();
            $(".ccdList-page").pullToRefresh({
                onRefresh: function () { /* 当下拉刷新触发的时候执行的回调 */
                    $("#ccd-list").empty();
                    getCCDList("");
                    $(".ccdList-page").pullToRefreshDone();
                },
                onPull: function (percent) { /* 用户下拉过程中会触发，接收一个百分比表示用户下拉的比例 */
                },
                distance: 50 /* 下拉刷新的触发距离， 注意，如果你重新定义了这个值，那么你需要重载一部分CSS才可以，请参考下面的自定义样式部分 */
            });

        })

        function getCCDList() {
            $("#ccd-list").empty();
            var types = [];
            $.showLoading();

            var params = {
                "id": common.getQueryString("id"),
                "select_type": select_type
            };
            $.post(navRoot + "/api/inpatient/sheet/list", params, function (data) {
                if (data["code"] == 200) {
                    var list = [];
                    try {
                        if (data["data"]["List"]) {

                            var dataObj = data["data"]["List"]["RequisitionFindResult"]["MedicalRequestInfo"]["RequestInfo"];
                            var patientInfo = data["data"]["List"]["RequisitionFindResult"]["PatientInfo"];
                            if (!dataObj.hasOwnProperty("length")) {
                                list[0] = dataObj;
                            } else {
                                list = dataObj;
                            }
                            cacheDataList = list;
                            for (var i in list) {
                                var requestInfo = list[i];
                                var typeItem = $('<div class="weui-well weui-well_access type' + exam_ScheduleID + '">' +
                                    '<div class="weui-well__top weui-flex">' +
                                    '    <div class="weui-flex__item inOrOutTime">' + requestInfo["ExamList"]["Exam"]["ExamProject"] + '</div>' +
                                    '    <div class="exam_state font12 font-bold text-common">' + '</div>' +
                                    '</div>' +
                                    '<div class="weui-well__content">' +
                                    '   <div class="weui-flex">' +
                                    '       <div class="weui-flex__item font12 text-disabled">临床诊断：' + requestInfo["LinChuangZhenDuan"] + '</div>' +
                                    '   </div>' +
                                    '<div class="weui-well__footer weui-flex">' +
                                    '       <div class="weui-flex__item font12 text-disabled">预约时间：' + common.dateFormart(requestInfo["ReservationInfo"]["resDate"], "yyyy-MM-dd") + " " + common.dateFormart(requestInfo["ReservationInfo"]["resTime"]) + '</div>' +
                                    '       <button class="baodaoBtn weui-btn weui-btn_mini">报到</button>' +
                                    '</div>' +
                                    '</div>'
                                );
                                var resDate = common.dateFormart(requestInfo["ReservationInfo"]["resDate"], 'yyyy-MM-dd');
                                var resTime = requestInfo["ReservationInfo"]["resTime"];
                                if (resDate && resTime && resTime.split("-").length > 1 && common.isOutTime(resDate, resTime.split("-")[1])) {
                                    typeItem.find(".baodaoBtn").addClass("weui-btn_disabled");
                                    typeItem.find(".baodaoBtn").click(function (event) {
                                        event.preventDefault();
                                        event.stopPropagation();
                                        $.alert("报到时间已过，请重新预约");
                                    });
                                } else if (resDate && resTime && resTime.split("-").length > 1 && common.isDaoTime(resDate, resTime.split("-")[0])) {
                                    typeItem.find(".baodaoBtn").addClass("weui-btn_disabled");
                                    typeItem.find(".baodaoBtn").click(function (event) {
                                        event.preventDefault();
                                        event.stopPropagation();
                                        $.alert("报到时间未到，请预约时间进行操作");
                                    });
                                } else {
                                    typeItem.find(".baodaoBtn").data("data", requestInfo);
                                    typeItem.find(".baodaoBtn").click(function (event) {
                                        event.preventDefault();
                                        event.stopPropagation();
                                        var requestInfo = $(this).data("data");
                                        var params = {
                                            "code": requestInfo["SheetID"],
                                            "scheduleID": requestInfo["ScheduleID"],
                                            "type": select_type
                                        };
                                        $.post(navRoot + "/api/inpatient/baodao", params, function (data) {
                                            if (data["code"] == 200) {
                                                var result = data["data"];
                                                sessionStorage.setItem("list_scrollTop", $(".ccdList-page").scrollTop());
                                                sessionStorage.setItem("list_type", select_type);
                                                sessionStorage.setItem("list_time", select_time);
                                                location.href = navRoot + "/info?id=" + params["code"] + "&type=" + params["type"] + "&queueName=" + result["QueueName"] + "&queueNumber=" + result["QueueNumber"];
                                            } else {
                                                $.alert(data["errmsg"]);
                                            }
                                        }, "json")
                                    })
                                }
                                var examState = requestInfo["ExamList"]["Exam"]["ExamState"];
                                if (examState == "1") {
                                    typeItem.find(".exam_state").text("未报到");
                                } else if (examState == "2") {
                                    typeItem.find(".exam_state").text("已报到");
                                } else if (examState == "3") {
                                    typeItem.find(".exam_state").text("已检查");
                                } else if (examState == "4") {
                                    typeItem.find(".exam_state").text("报告发布");
                                } else if (examState == "5") {
                                    typeItem.find(".exam_state").text("退检");
                                }
                                typeItem.data("info", requestInfo);
                                typeItem.click(function () {
                                    var id = $(this).data("info")["SheetID"];
                                    var type = $(this).data("info")["RequisitionType"];
                                    sessionStorage.setItem("list_scrollTop", $(".ccdList-page").scrollTop());
                                    sessionStorage.setItem("list_type", select_type);
                                    sessionStorage.setItem("list_time", select_time);
                                    location.href = navRoot + "/info?id=" + id + "&type=" + type;
                                });
                                $("#ccd-list").append(typeItem);

                            }
                            if ($("#ccd-list").children().length == 0) {
                                $("#ccd-list").append('<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>');
                            }
                        } else {
                            $("#ccd-list").append('<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>');
                        }
                        if (sessionStorage.getItem("list_scrollTop")) {
                            $(".ccdList-page").scrollTop(sessionStorage.getItem("list_scrollTop"));
                            sessionStorage.removeItem("list_scrollTop");
                        }
                    } catch (err) {
                        $.alert("数据错误:" + err);
                    }
                } else if (data["code"] == 501) {
                    $("#ccd-list").append('<div class="weui-loadmore weui-loadmore_line"><span class="weui-loadmore__tips">暂无数据</span></div>');
                } else {
                    $.alert(data["errmsg"]);
                }
                $.hideLoading();
            }, "json")
        }
    </script>
{% endblock %}